package com.learn.security.controller;

import com.learn.security.bo.ApiResult;
import com.learn.security.bo.LoginInfo;
import com.learn.security.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * @author : Yu.Tan
 * @date : 2022/12/9 16:02
 * @desc : **
 */
@RestController
@RequestMapping("/v1")
public class SysLoginController {

    @Autowired
    private AuthService authService;

    @PostMapping("/login")
    public ApiResult login(@Valid @RequestBody LoginInfo loginInfo) {
        return authService.login(loginInfo.getLoginAccount(), loginInfo.getPassword());
    }

    public static void main(String[] args) {
        List<LoginInfo> loginInfoList=new ArrayList<>();
        LoginInfo loginInfo=new LoginInfo();
        loginInfo.setLoginAccount("测试1");
        loginInfoList.add(loginInfo);

        LoginInfo loginInfo1=new LoginInfo();
        loginInfo1.setLoginAccount("测试2");
        loginInfoList.add(loginInfo1);

        LoginInfo loginInfo3=new LoginInfo();
        loginInfo3.setLoginAccount("测试3");
        loginInfoList.add(loginInfo3);

        loginInfoList.forEach(r->{
            r.setPassword("123");
        });

        for (LoginInfo info : loginInfoList) {
            System.out.println(info);
        }
    }
}
